(function($) {	
	$.extend({
		ajaxMutilSelect: function(toId,url,pars,type,evalScript,defaultValue) {			
			//$.setLoadingImg(url,toId);	
			$("#request_url").html(url);	
			$.ajax({
				url: url,
				type: (type === null || type === '')?'GET':type,
				dataType: 'json',
				data: pars,
				evalScripts: (evalScript === false)?false:true,
				error: function(){
					$.setLoadingImg('Error?Reload?');
				},
				success: function(html){
					if(html !== null && html !== "" && html !== false){	
						$('#'+toId).empty();
						$.each(html, function(i, n){
						  if(i === -99){
						  	i = n;
						  }
		                  $('#'+toId).append("<option value='"+i+"' label='"+n+"'>"+n+"</option>");
		                });
		                if(defaultValue !== null && defaultValue !== '' && defaultValue !== false){
		                	$('#'+toId).val(defaultValue);
		                }
	                }
				}
			});
			return false;
		},		
		ajaxRequest: function(toId,url,pars,type,evalScript) {			
			//$.setLoadingImg(url,toId);	
			$.phpnetRemoveAd();
			$("#request_url").html(url);	
			$.ajax({
				url: url,
				type: (type === null || type === '' || type === 'undefined')?'GET':type,
				dataType: 'html',
				data: pars,
				evalScripts: (evalScript === false)?false:true,
				error: function(){
					$.setLoadingImg('Error?Reload?');
				},
				success: function(html){					
					html = $.phpnetRemoveAd(html);
					$('#'+toId).html(html);					
					toId_array = toId.split("_");
					if('dialog' == toId_array[0]){
						$('#'+toId).dialog({width: 300, height: 600}).dialog('open');
					}else if('draggable' == toId_array[0]){
						$('#'+toId).draggable('enable').show();
					}					
				}
			});
			return false;
		},		
		ajaxFormRequest:function(toId,url,form,evalScript){
			//pars = $("#"+form).formSerialize();
			var pars = $("#"+form).serialize();
			$.ajaxRequest(toId,url,pars,'POST',evalScript);
		},
		ajaxItemRequest:function(item,table,path,evalScript){
			var value = $('#'+item).val();
			var url = path+'/i/'+item+'/v/'+value+'/t/'+table;
			var toId = item+'result';
			$.ajaxRequest(toId,url,'','GET',evalScript);
		},		
		setLoadingImg:function(url,toId){
			if(toId != ''){
				var _loadImg = '<IMG alt="loading" src="'+_baseUrl+'/public/images/icons/loading.gif" border=0 >';
				$('#'+toId).html(_loadImg);
			}
		},
		joinUrlWithParam:function(url,param){
			if(param !== null && param !== ""){			
				if(url.lastIndexOf("?") < 0){
					url += "?" + param;
				}else{
					url += "&" + param;
				}
			}
			return url;
		},		
		phpnetRemoveAd:function (html){
			if(html != '' && html != null && html != 'undefined'){
				var iframe_start = html.indexOf("<IFRAME");
				var iframe_end = html.indexOf("</IFRAME>");
				//var script_last_end = html.lastIndexOf("</SCRIPT>")+"</SCRIPT>".length;
				var div_start = html.lastIndexOf('<div style="text-align: center;">');
				var div_end = html.lastIndexOf("</div>")+"</div>".length;
				if(iframe_start >0  && iframe_end >0){
					var html_1 = html.substr(0,div_start);
					var html_2 = html.substr(div_end ,html.length);
					html = html_1 + html_2;
				}
				return html;
			}else{
				$("iframe").parent().parent().parent().parent().remove();
			}
		}
	});
})(jQuery);

$(document).ready(function() {
	$("#loading").bind("ajaxSend", function(){
		$(this).show();
	}).bind("ajaxComplete", function(){
		$(this).fadeOut('slow');
	});
});